import json
from django.conf import settings
from .base import Base


class GetData(Base):
    def __init__(self, data):
        super(GetData, self).__init__(data)
        self.wait_num = 60

    def struct_msg(self):
        string, time = self.mission.description.split("/")
        if time:
            date, hour = time.split(",")
        else:
            date, hour = "", ""
        msg = {"TID": self.tid,
               "STRING": string,
               "DATE": date,
               "HOUR": hour
               }
        msg = json.dumps(msg)
        return msg

    def struct_pub_topic(self):
        notify = "notify"
        gid = "".join(["/", self.gateway_id, "/"])
        func = "wave"
        topic = "".join([notify, gid, func])
        return topic

    def struct_sub_topic(self):
        notify = "notifyed"
        gid = "".join(["/", self.gateway_id, "/"])
        func = "wave"
        topic = "".join([notify, gid, func])
        return topic
